Imports System.Data.OleDb
Imports DTO
Public Class NhanVienDAO
    Inherits AbstractDAO

    Public Sub New()

    End Sub
    Public Function LayBang(ByVal username, ByVal password) As DataTable
        Dim dt As New DataTable
        Dim cn As OleDbConnection
        cn = AbstractDAO.ConnectionData()
        Dim strSQL As String
        strSQL = "select * from NhanVien where Username='" + username + "' and Password='" + password + "'"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        da.Fill(dt)
        cn.Close()
        

        Return dt
    End Function
    Public Function LayDanhSach() As IList
        Dim ds As New ArrayList
        Dim cn As OleDbConnection
        cn = AbstractDAO.ConnectionData()
        Dim strSQL As String
        strSQL = "select * from NhanVien"
        Dim cmb As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmb.ExecuteReader()
        While (dr.Read())
            Dim nvDto As New NhanVienDTO
            nvDto.MaNhanVien = dr("MaNhanVien")
            nvDto.Username = dr("Username")
            nvDto.Password = dr("Password")
            nvDto.HoTen = dr("HoTen")
            ds.Add(nvDto)
        End While
        dr.Close()
        cn.Close()
        Return ds
    End Function
    Public Sub CapNhatBang(ByVal dt As DataTable)
        Dim cn As OleDbConnection
        cn = AbstractDAO.ConnectionData()
        Dim strSQL As String
        strSQL = "select * from NhanVien"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        Dim cmb As New OleDbCommandBuilder(da)
        da.Update(dt)
        cn.Close()
    End Sub
End Class
